package edu.bbu.bibliospring.api.cdiassembler;

import edu.bbu.bibliospring.api.resources.TestResource;
import edu.bbu.bibliospring.backend.model.Profile;
import edu.bbu.bibliospring.common.dto.ProfileDto;
import org.apache.log4j.Logger;

/**
 * Created by erika on 6/13/14.
 * Assembler class transforming the model and dto of the Profile entity
 */
public class ProfileAssembler implements Assembler<Profile, ProfileDto> {

    private static final Logger LOG = Logger.getLogger(TestResource.class);

    @Override
    public Profile createModel() {
        LOG.info("ProfileAssembler - new Profile created");
        return new Profile();
    }

    @Override
    public ProfileDto createDto() {
        LOG.info("ProfileAssembler - new ProfileDto created");
        return new ProfileDto(Profile.class.getName());
    }

    @Override
    public ProfileDto modelToDto(Profile model) {
        LOG.info("ProfileAssembler - modelToDto");
        ProfileDto profileDto = createDto();
        profileDto.setId(model.getId());
        profileDto.setFirstName(model.getFirstName());
        profileDto.setLastName(model.getLastName());
        profileDto.setRole(model.getRole());
        profileDto.setUsername(model.getUsername());
        profileDto.setPassword(model.getPassword());
        return profileDto;
    }

    @Override
    public Profile dtoToModel(ProfileDto dto) {
        LOG.info("ProfileAssembler - dtoToModel");
        Profile profile = createModel();
        profile.setId(dto.getId());
        profile.setUsername(dto.getUsername());
        profile.setPassword(dto.getPassword());
        profile.setFirstName(dto.getFirstName());
        profile.setLastName(dto.getLastName());
        profile.setRole(dto.getRole());
        return profile;
    }
}
